namespace IAM.Interface.Model
{
    using IAM.Interface.Common;
    using IAM.Interface.Model.ENUM;
    using IAM.Interface.Model.Interface;
    using System;
    using System.Text;

    [Serializable]
    public class RequestData : AbstractConvertObject, IConvertXml
    {
        private IAM.Interface.Model.ENUM.ActionType _actiontype = IAM.Interface.Model.ENUM.ActionType.AUDIT_FETCH;
        private string _appname = "";
        private DateTime _requesttime = DateTime.Now;
        private string _token = "";
        private string _transactionid = "";

        public override object ConvertToObject()
        {
            this.TransactionID = EnDeCoding.Decode(this.CurrentXmlNode.Attributes["TransactionID"].InnerText);
            this.RequestTime = Convert.ToDateTime(this.CurrentXmlNode.Attributes["RequestTime"].InnerText);
            this.AppName = EnDeCoding.Decode(this.CurrentXmlNode.Attributes["AppName"].InnerText);
            this.Token = EnDeCoding.Decode(this.CurrentXmlNode.Attributes["Token"].InnerText);
            switch (this.CurrentXmlNode.Attributes["ActionType"].InnerText.ToLower())
            {
                case "audit_fetch":
                    this.ActionType = IAM.Interface.Model.ENUM.ActionType.AUDIT_FETCH;
                    break;

                case "dm_getdeleinfo":
                    this.ActionType = IAM.Interface.Model.ENUM.ActionType.DM_GETDELEINFO;
                    break;

                case "dm_getmodulelist":
                    this.ActionType = IAM.Interface.Model.ENUM.ActionType.DM_GETMODULELIST;
                    break;

                case "dm_setdeleinfo":
                    this.ActionType = IAM.Interface.Model.ENUM.ActionType.DM_SETDELEINFO;
                    break;

                case "iden_getacmodel":
                    this.ActionType = IAM.Interface.Model.ENUM.ActionType.IDEN_GETACMODEL;
                    break;

                case "iden_getlist":
                    this.ActionType = IAM.Interface.Model.ENUM.ActionType.IDEN_GETLIST;
                    break;

                case "iden_getuseraci":
                    this.ActionType = IAM.Interface.Model.ENUM.ActionType.IDEN_GETUSERACI;
                    break;

                case "iden_manage":
                    this.ActionType = IAM.Interface.Model.ENUM.ActionType.IDEN_MANAGE;
                    break;

                case "iden_setuseraci":
                    this.ActionType = IAM.Interface.Model.ENUM.ActionType.IDEN_SETUSERACI;
                    break;

                case "org_create":
                    this.ActionType = IAM.Interface.Model.ENUM.ActionType.ORG_CREATE;
                    break;

                case "org_delete":
                    this.ActionType = IAM.Interface.Model.ENUM.ActionType.ORG_DELETE;
                    break;

                case "org_update":
                    this.ActionType = IAM.Interface.Model.ENUM.ActionType.ORG_UPDATE;
                    break;
            }
            return this;
        }

        public IAM.Interface.Model.ENUM.ActionType ActionType
        {
            get
            {
                return this._actiontype;
            }
            set
            {
                this._actiontype = value;
            }
        }

        public string AppName
        {
            get
            {
                return this._appname;
            }
            set
            {
                this._appname = value;
            }
        }

        public DateTime RequestTime
        {
            get
            {
                return this._requesttime;
            }
            set
            {
                this._requesttime = value;
            }
        }

        public string Token
        {
            get
            {
                return this._token;
            }
            set
            {
                this._token = value;
            }
        }

        public string TransactionID
        {
            get
            {
                return this._transactionid;
            }
            set
            {
                this._transactionid = value;
            }
        }

        public string XML
        {
            get
            {
                return (this.XMLBoday + this.XMLFinis);
            }
        }

        public string XMLBoday
        {
            get
            {
                StringBuilder xml = new StringBuilder();
                xml.Append(" <RequestData");
                xml.Append(" TransactionID=\"" + EnDeCoding.Encode(this.TransactionID) + "\"");
                xml.Append(" RequestTime=\"" + this.RequestTime.ToString() + "\"");
                xml.Append(" AppName=\"" + EnDeCoding.Encode(this.AppName) + "\"");
                xml.Append(" Token=\"" + EnDeCoding.Encode(this.Token) + "\"");
                xml.Append(" ActionType=\"" + this.ActionType.ToString() + "\"");
                xml.Append(" >");
                return xml.ToString();
            }
        }

        public string XMLFinis
        {
            get
            {
                return "</RequestData>";
            }
        }
    }
}
